#include <mockcpp/mockcpp.hpp>
#include <testngpp/testngpp.hpp>
#include <Rectangle.h>
#include <Decimal.h>
#include "float.h"

USING_MOCKCPP_NS
USING_TESTNGPP_NS

FIXTURE(Rectangle)
{
        TEST(area invalid of constructing an invalid rectangle(100.05,3.22678))
	{
		Rectangle rectangle(100.05,3.22678);

		ASSERT_EQ(0,rectangle.getArea());
	}

	TEST(Perimeter invalid of constructing an invalid rectangle(100.05,3.22678))
	{
		Rectangle rectangle(100.05,3.22678);

		ASSERT_EQ(0,rectangle.getPerimeter());
	}

	TEST(should be able to calculate the area of the rectangle(2.11789,3.22678))
	{
		Rectangle rectangle(2.13789,3.22678);

		ASSERT_EQ(true,(abs(6.86-rectangle.getArea())<FLT_EPSILON));
	}

	TEST(should be able to calculate the perimeter of the rectangle(2.11789,3.22678))
	{
		Rectangle rectangle(2.11789,3.22678);

		ASSERT_EQ(true,(abs(2*(2.11+3.22)-rectangle.getPerimeter())<FLT_EPSILON));
	}

	TEST(should be able to modify the side length of the rectangle(2.11789,3.22678))
	{
		Rectangle rectangle(2.13789,3.22678);
                rectangle.setLength(3.7651);
                rectangle.setWidth(4.2137);
		ASSERT_EQ(true,(abs(15.83-rectangle.getArea())<FLT_EPSILON));
                ASSERT_EQ(true,(abs(2*(3.76+4.21)-rectangle.getPerimeter())<FLT_EPSILON));
	}

	TEST(original side length kept when set invalid length(-1.234,100.345))
	{
		Rectangle rectangle(2.11789,3.22678);
                rectangle.setLength(-1.234);
                rectangle.setWidth(100.345);

		ASSERT_EQ(true,(abs(6.86-rectangle.getArea())<FLT_EPSILON));
                ASSERT_EQ(true,(abs(2*(2.11+3.22)-rectangle.getPerimeter())<FLT_EPSILON));
	}

	TEST(length can be modified even the width is invalid(3.2145,100.345))
	{
		Rectangle rectangle(2.11789,3.22678);
                rectangle.setLength(3.2145);
                rectangle.setWidth(100.345);

		ASSERT_EQ(true,(abs(10.34-rectangle.getArea())<FLT_EPSILON));
                ASSERT_EQ(true,(abs(2*(3.21+3.22)-rectangle.getPerimeter())<FLT_EPSILON));
	}

	TEST(width can be modified even the length is invalid(-1.234,5.1678))
	{
		Rectangle rectangle(2.11789,3.22678);
                rectangle.setLength(-1.234);
                rectangle.setWidth(5.1678);

		ASSERT_EQ(true,(abs(10.89-rectangle.getArea())<FLT_EPSILON));
                ASSERT_EQ(true,(abs(2*(2.11+5.16)-rectangle.getPerimeter())<FLT_EPSILON));
	}
};
